package com.shujunjun.project.controller;

import com.shujunjun.project.entity.Project;
import com.shujunjun.project.service.IProjectService;
import com.shujunjun.project.strategy.junjun.IJunJunService;
import com.shujunjun.project.strategy.junjun.JunJunFactory;
import com.shujunjun.project.strategy.more.More;
import com.shujunjun.project.strategy.more.MoreStrategy;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequiredArgsConstructor
public class ProjectController {

    @Resource
    private DiscoveryClient discoveryClient;

    final IProjectService projectService;

    final JunJunFactory junJunFactory;

    final MoreStrategy moreStrategy;

    @GetMapping(value = "services")
    public List<String> getServices() {
        return discoveryClient.getServices();
    }

    @GetMapping(value = "project")
    public List<Project> project() {
        return projectService.list();
    }

    @GetMapping(value = "junjun")
    public void junjun(String name) {
        IJunJunService invokeStrategy = junJunFactory.getInvokeStrategy(name);
        invokeStrategy.doSomething(name);
    }

    @GetMapping(value = "more")
    public String more1(String name) {
        More moreInstance = moreStrategy.getMoreInstance(name);
        Integer i = moreInstance.method2(10);
        log.info("值：{}", i);
        return moreInstance.method1(name);
    }
}
